﻿// Altimeter - 高度表

#include "Altimeter.h"

//// 定义表盘半径
//#define DIAL_RADIUS 163
//// 定义圆心坐标
//#define CENTER_X 1764
//#define CENTER_Y 332

// 基准参数（可修改这三个值实现缩放/移动）
const double DIAL_RADIUS_BASE = 180.0;
const double CENTER_X_BASE = 400.0;
const double CENTER_Y_BASE = 300.0;


void drawAM(float x, float y, float r, float height) {

    //initgraph(800, 600);
    //setrendermode(RENDER_MANUAL);
    //setbkcolor(EGERGB(76, 76, 76));
    //ege_setpattern_ellipsegradient(ege_point{ CENTER_X , CENTER_Y }, EGEACOLOR(0xFF, BLACK), 200, 100, 460, 460, EGEACOLOR(0, WHITE));
    //ege_fillrect(30, 30, 700, 700);
   // outerCircle();//外边框
    double current_heading = 0;
    //for (; is_run(); delay_fps(60))
    //{
    //    cleardevice();
        heightToAngle(height);
        heightToAngle2(height);
        heightToAngle3(height);
        drawInnerScaleAndNumbers(current_heading, x, y, r);//数字与刻度2
        fillpie2(x, y, r);
        drawInnerScaleAndNumbers2(current_heading, x, y, r);
        fillpie1(x, y, r);
        lineN(x, y, r);
        innercircle(x, y, r);//内部小盘
        drawScaleAndNumbers(x, y, r);//数字与刻度1
        shadowAM(x, y, r);
        drawButton(x, y, r);
        outerCircle(x, y, r);//外边框

        current_heading = updateheadingAM(current_heading);//数据变化模拟

        ten_thousand(height, x, y, r);
        hundred(height, x, y, r);
        thousand(height, x, y, r);
       

    //    getch();
    //}
    //closegraph();
    //return 0;
}

//数字与刻度大盘
void drawScaleAndNumbers(float  CENTER_X, float CENTER_Y, float DIAL_RADIUS) {
    double dialRadius = DIAL_RADIUS;
    double centerX = CENTER_X;
    double centerY = CENTER_Y;
    setbkmode(TRANSPARENT);//去除文字背景色

    // 计算比例因子（相对于基准半径）
    const double scale = dialRadius / DIAL_RADIUS_BASE;

    // 基础样式设置
    setcolor(EGERGB(210, 210, 210));
    setlinewidth(3 * scale); // 小刻度线宽（带比例）
    ege_enable_aa(TRUE);
    char numStr[2] = { 0 };

    // --------------------------- 绘制刻度 ---------------------------
    // 小刻度（7.2°间隔）
    for (double i = 0; i < 360; i += 7.2) {
        const double angle = i * M_PI / 180 - M_PI / 2; // 弧度，12点方向起始
        const double r_inner = dialRadius - (i > 79 && i < 101 ? 5.0 : 20.0) * scale; // 内半径（带比例）

        // 计算刻度端点（浮点坐标，六位小数）
        const double x1 = centerX + r_inner * cos(angle);
        const double y1 = centerY + r_inner * sin(angle);
        const double x2 = centerX + dialRadius * cos(angle);
        const double y2 = centerY + dialRadius * sin(angle);

        ege_line(x1, y1, x2, y2);
    }

    // 大刻度（36°间隔）
    setlinewidth(5 * scale); // 大刻度线宽（带比例）
    for (int i = 0; i < 360; i += 36) {
        const double angle = i * M_PI / 180 - M_PI / 2;
        const double r_inner = dialRadius - 30.0 * scale; // 内半径（带比例）

        // 计算刻度端点
        const double x1 = centerX + r_inner * cos(angle);
        const double y1 = centerY + r_inner * sin(angle);
        const double x2 = centerX + dialRadius * cos(angle);
        const double y2 = centerY + dialRadius * sin(angle);

        ege_line(x1, y1, x2, y2);

        // --------------------------- 绘制数字 ---------------------------
        if (i % 36 == 0) {
            int num = i / 36;
            if (num == 0) num = 0;
            sprintf(numStr, "%d", num);

            // 字体设置（带比例）
            setfont(40 * scale, 22 * scale, "MS UI Gothic");
            const int textWidth = textwidth(numStr);
            const int textHeight = textheight(numStr);

            // 计算文本基准点（相对于圆心）
            const double r_text = dialRadius - 45.0 * scale; // 文本半径（带比例）
            const double tx = r_text * cos(angle);
            const double ty = r_text * sin(angle);

            // 文本位置调整（带比例偏移）
            if (strcmp(numStr, "2") == 0 || strcmp(numStr, "8") == 0) {
                outtextxy(centerX + tx - textWidth / 2 + 10 * scale,
                    centerY + ty - textHeight / 2 - 5 * scale, numStr);
            }
            else if (strcmp(numStr, "3") == 0 || strcmp(numStr, "7") == 0) {
                outtextxy(centerX + tx - textWidth / 2 + 10 * scale,
                    centerY + ty - textHeight / 2 + 35 * scale, numStr);
            }
            else if (strcmp(numStr, "0") == 0) {
                outtextxy(centerX + tx - textWidth / 2,
                    centerY + ty - textHeight / 2 + 18 * scale, numStr);
            }
            else {
                outtextxy(centerX + tx - textWidth / 2 + 10 * scale,
                    centerY + ty - textHeight / 2 + 25 * scale, numStr);
            }
        }
    }

    // --------------------------- 绘制单位文本 ---------------------------
    setfont(13 * scale, 8 * scale, "黑体");
    const double text_offset = 31.0 * scale; // 基准偏移量（带比例）

    // 左侧单位
    outtextxy(centerX - (dialRadius - text_offset), centerY - 5 * scale, "mb");
    outtextxy(centerX - (dialRadius - text_offset), centerY + 2 * scale, "-");

    // 右侧单位
    const double text_offset_right = 61.0 * scale;
    outtextxy(centerX + (dialRadius - text_offset_right), centerY - 8 * scale, "IN.Hg");
    outtextxy(centerX + (dialRadius - text_offset_right), centerY + 2 * scale, "-");

    // --------------------------- 绘制旋转文本 ---------------------------
    // 顺时针旋转20°文本（escapement单位：0.1°）
    setfont(-18 * scale, 0, "MS UI Gothic",
        20 * 10, 20 * 10, 500, false, false, false);
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    ege_outtextxy(centerX - 50 * scale, centerY - 140 * scale, "100"); // 相对于圆心偏移

    // 逆时针旋转20°文本
    setfont(-18 * scale, 0, "MS UI Gothic",
        -20 * 10, -20 * 10, 500, false, false, false);
    ege_outtextxy(centerX + 50 * scale, centerY - 140 * scale, "FEET"); // 相对于圆心偏移
}
//刻度与数字
void drawInnerScaleAndNumbers(double current_heading, float  CENTER_X, float CENTER_Y, float DIAL_RADIUS) {
    // 转换为double并保留六位小数
    setbkmode(TRANSPARENT);//去除文字背景色

    const double dialRadius = DIAL_RADIUS;
    const double centerX = CENTER_X;
    const double centerY = CENTER_Y;

    // 填充黑色背景
    setfillcolor(EGERGB(40, 40, 40));
    ege_fillcircle(centerX, centerY, dialRadius - 7.0 * (dialRadius / 180));

    // 基础样式
    setcolor(EGERGB(210, 210, 210));
    setlinewidth(0.5 * (dialRadius / 180)); // 小刻度线宽（固定值，如需随半径缩放可改为 0.5 * (dialRadius/180)）
    ege_enable_aa(TRUE);
    char numStr[5] = { 0 };

    // --------------------------- 绘制小刻度（2°间隔） ---------------------------
    for (double i = 0; i < 360; i += 2.0) {
        const double angle = (i + current_heading) * M_PI / 180.0; // 弧度，12点方向起始
        const double r_inner = dialRadius - 37.0 * (dialRadius / 180); // 内半径（固定偏移）
        const double r_outer = dialRadius - 32.0 * (dialRadius / 180); // 外半径（固定偏移）

        // 计算刻度端点（浮点坐标，六位小数）
        const double x1 = centerX + r_inner * cos(angle);
        const double y1 = centerY + r_inner * sin(angle);
        const double x2 = centerX + r_outer * cos(angle);
        const double y2 = centerY + r_outer * sin(angle);

        ege_line(x1, y1, x2, y2);
    }

    // --------------------------- 绘制大刻度（10°间隔） ---------------------------
    setlinewidth(2.0 * (dialRadius / 180)); // 大刻度线宽（固定值）
    for (int i = 0; i < 360; i += 10) {
        const double angle = (i + current_heading) * M_PI / 180.0;
        const double r_inner = dialRadius - 37.0 * (dialRadius / 180);
        const double r_outer = dialRadius - 32.0 * (dialRadius / 180);

        // 绘制大刻度
        ege_line(
            centerX + r_inner * cos(angle), centerY + r_inner * sin(angle),
            centerX + r_outer * cos(angle), centerY + r_outer * sin(angle)
        );

        // --------------------------- 绘制旋转数字 ---------------------------
        const double value = 28.0 + (i / 360.0) * 3.6; // 数值计算
        snprintf(numStr, sizeof(numStr), "%.1f", value); // 保留一位小数

        // 文本位置（更外侧半径）
        const double text_radius = dialRadius - 18.0 * (dialRadius / 180); // 文本半径
        const double textX = centerX + text_radius * cos(angle);
        const double textY = centerY + text_radius * sin(angle);

        // 字体旋转（escapement单位：0.1°，顺时针旋转(i+current_heading)度）
        setfont(
            -13.0 * (dialRadius / 180),                // 字体高度（负值忽略行距）
            0.0,                  // 字符宽度自动
            L"MS UI Gothic",       // 字体名称（宽字符版本）
            static_cast<int>(-(i + current_heading) * 10.0), // escapement（0.1°单位）
            static_cast<int>(-(i + current_heading) * 10.0), // orientation
            FW_NORMAL,            // 字体粗细
            FALSE, FALSE, FALSE    // 非斜体、无下划线、无删除线
        );

        settextjustify(CENTER_TEXT, CENTER_TEXT);
        ege_outtextxy(textX, textY, numStr);
    }
}
void drawInnerScaleAndNumbers2(double current_heading, float  CENTER_X, float CENTER_Y, float DIAL_RADIUS) {
    const double dialRadius = DIAL_RADIUS;
    const double centerX = CENTER_X;
    const double centerY = CENTER_Y;
    setbkmode(TRANSPARENT);//去除文字背景色

    // 填充黑色背景
    setfillcolor(EGERGB(40, 40, 40));
    ege_fillcircle(centerX, centerY, dialRadius - 40.0 * (dialRadius / 180));

    // 基础样式
    setcolor(EGERGB(210, 210, 210));
    setlinewidth(0.5 * (dialRadius / 180));
    ege_enable_aa(TRUE);
    char numStr[5] = { 0 };

    // --------------------------- 绘制小刻度（2°间隔，带180°偏移） ---------------------------
    for (double i = 0; i < 360; i += 2.0) {
        const double angle = (i + current_heading + 180.0) * M_PI / 180.0; // 反向角度
        const double r_inner = dialRadius - 50.0 * (dialRadius / 180);
        const double r_outer = dialRadius - 45.0 * (dialRadius / 180);

        ege_line(
            centerX + r_inner * cos(angle), centerY + r_inner * sin(angle),
            centerX + r_outer * cos(angle), centerY + r_outer * sin(angle)
        );
    }

    // --------------------------- 绘制大刻度（10°间隔） ---------------------------
    setlinewidth(2.0 * (dialRadius / 180));
    for (int i = 0; i < 360; i += 10) {
        const double angle = (i + current_heading + 180.0) * M_PI / 180.0;
        const double r_inner = dialRadius - 50.0 * (dialRadius / 180);
        const double r_outer = dialRadius - 45.0 * (dialRadius / 180);

        ege_line(
            centerX + r_inner * cos(angle), centerY + r_inner * sin(angle),
            centerX + r_outer * cos(angle), centerY + r_outer * sin(angle)
        );

        // --------------------------- 绘制旋转数字 ---------------------------
        const double value = 950.0 + (i / 10.0) * 5.0; // 数值计算
        snprintf(numStr, sizeof(numStr), "%.1f", value);

        // 文本位置（调整后的半径）
        const double text_radius = dialRadius - 65.0 * (dialRadius / 180); // 原逻辑：20+45=65（需确认是否合理）
        const double textX = centerX + text_radius * cos(angle);
        const double textY = centerY + text_radius * sin(angle);

        // 字体旋转（与角度同步反向）
        setfont(
            -13.0 * (dialRadius / 180),
            0.0,
            L"MS UI Gothic",
            static_cast<int>(-(i + current_heading) * 10.0),
            static_cast<int>(-(i + current_heading) * 10.0),
            FW_NORMAL,
            FALSE, FALSE, FALSE
        );

        settextjustify(CENTER_TEXT, CENTER_TEXT);
        ege_outtextxy(textX, textY, numStr);
    }
}
//内部填充圆
void innercircle(float  CENTER_X, float CENTER_Y, float DIAL_RADIUS) {
    ege_enable_aa(TRUE);
    setbkmode(TRANSPARENT);//去除文字背景色

    const double dialRadius = DIAL_RADIUS;
    const double centerX = CENTER_X;
    const double centerY = CENTER_Y;
    double scale = dialRadius / DIAL_RADIUS_BASE; // 比例因子

    // 计算内圆参数（相对于圆心）
    double innerRadius = dialRadius - 80 * scale;
    double pieX = centerX - innerRadius;
    double pieY = centerY - innerRadius;
    double pieWidth = 2 * innerRadius;

    // 绘制扇形
    setfillcolor(EGERGB(55, 55, 55));
    ege_fillpie(pieX, pieY, pieWidth, pieWidth, 120, 300); // 角度固定，半径参数化

    // 绘制文本（相对于圆心的偏移量）
    setcolor(EGERGB(210, 210, 210));
    setfont(33 * scale, 20 * scale, L"楷体");
    outtextxy(centerX - 50 * scale, centerY - 50 * scale, L"ALT"); // 原350=400-50，250=300-50

    setfont(9 * scale, 7 * scale, L"楷体");
    outtextxy(centerX - 50 * scale, centerY - 20 * scale, L"CALIBRATED"); // 原280=300-20
    outtextxy(centerX - 50 * scale, centerY - 10 * scale, L"  TO");
    outtextxy(centerX - 50 * scale, centerY, L"20 000"); // 原300=300+0
}
//黑白排线
void lineN(float  CENTER_X, float CENTER_Y, float DIAL_RADIUS) {
    const double dialRadius = DIAL_RADIUS;
    const double centerX = CENTER_X;
    const double centerY = CENTER_Y;
    ege_enable_aa(TRUE);
    double scale = dialRadius / DIAL_RADIUS_BASE;
    double n = 30 * scale; // 原n=30，随半径缩放

    // 绘制扇形（与innercircle类似的内圆）
    double innerRadius = dialRadius - 80 * scale;
    setfillcolor(EGERGB(210, 210, 210));
    ege_fillpie(centerX - innerRadius, centerY - innerRadius,
        2 * innerRadius, 2 * innerRadius, 60, 60); // 固定角度

    // 绘制线条（相对于圆心的坐标）
    setcolor(EGERGB(46, 46, 46));
    setlinewidth(10 * scale);

    // 线条坐标参数化（原坐标转换为相对于圆心的偏移）
    ege_line(centerX + n, centerY,
        centerX - 4 * n, centerY + 100 * scale); // 原100为固定像素，可改为比例

    ege_line(centerX + 2 * n, centerY,
        centerX - 3 * n, centerY + 100 * scale);

    ege_line(centerX + 3 * n, centerY,
        centerX - 2 * n, centerY + 100 * scale);

    ege_line(centerX + 4 * n, centerY,
        centerX - n, centerY + 100 * scale);

    ege_line(centerX + 5 * n - 10 * scale, centerY + 10 * scale,
        centerX - 10 * scale, centerY + 10 * scale + 100 * scale);

    // 中心实心圆
    setfillcolor(EGERGB(55, 55, 55));
    ege_fillcircle(centerX, centerY, 40 * scale); // 原半径40
}
void outerCircle(float  CENTER_X, float CENTER_Y, float DIAL_RADIUS) {
    const double dialRadius = DIAL_RADIUS;
    const double centerX = CENTER_X;
    const double centerY = CENTER_Y;
    ege_enable_aa(TRUE);
    double scale = dialRadius / DIAL_RADIUS_BASE;

    // 绘制阴影和圆环（半径参数化）
    setcolor(BLACK);

    setlinewidth(5 * scale);
    ege_circle(centerX, centerY, dialRadius + 20 * scale + 14 * scale); // 原20+14=34
    setcolor(EGERGB(43, 43, 43));

    setlinewidth(25 * scale);
    ege_circle(centerX, centerY, dialRadius + 20 * scale); // 原+20
    setcolor(EGERGB(17, 17, 17));

    setlinewidth(15 * scale);
    ege_circle(centerX, centerY, dialRadius + 20 * scale - 5 * scale); // 原-5
    setcolor(EGERGB(5, 5, 5));

    setlinewidth(4 * scale);
    ege_circle(centerX, centerY, dialRadius + 7 * scale); // 原+7


}
void drawButton(float  CENTER_X, float CENTER_Y, float DIAL_RADIUS) {
    ege_enable_aa(TRUE);
    const double dialRadius = DIAL_RADIUS;
    const double centerX = CENTER_X;
    const double centerY = CENTER_Y;
    double scale = dialRadius / DIAL_RADIUS_BASE;

    // 投影和按钮坐标参数化（原坐标转换为相对于圆心的偏移）
    double halfRadius = dialRadius / 2.0; // 原DIAL_RADIUS/2

    // 投影多边形
    ege_point points2[4] = {
        {centerX - dialRadius - 10 * scale, centerY + halfRadius + 10 * scale}, // 原-10、+10
        {centerX - dialRadius - 27 * scale, centerY + dialRadius - 4 * scale}, // 原-27、-4
        {centerX - halfRadius, centerY + dialRadius + 70 * scale}, // 原+70
        {centerX - 40 * scale, centerY + dialRadius + 30 * scale} // 原-40、+30
    };
    setfillcolor(EGERGB(30, 30, 30));
    ege_fillclosedcurve(4, points2, 0.25);

    // 按钮主体
    ege_point points[4] = {
        {centerX - dialRadius - 5 * scale, centerY + halfRadius + 20 * scale}, // 原-5、+20
        {centerX - dialRadius - 17 * scale, centerY + dialRadius - 4 * scale}, // 原-17、-4
        {centerX - halfRadius, centerY + dialRadius + 70 * scale}, // 同上
        {centerX - 40 * scale, centerY + dialRadius + 30 * scale} // 同上
    };
    setfillcolor(EGERGB(38, 38, 38));
    ege_fillclosedcurve(4, points, 0.25);

    // 按钮投影圆
    for (double i = 0; i < 20; i += 0.5) {
        setfillcolor(EGERGB(20, 20, 20));
        ege_fillcircle(centerX - halfRadius - 30 * scale - i * scale / 10, // 原-30、i/10
            centerY + dialRadius + 60 * scale - i, // 原+60、-i
            35 * scale); // 原半径35
    }
    setfillcolor(EGERGB(50, 50, 50));
    ege_fillcircle(centerX - halfRadius - 30 * scale,
        centerY + dialRadius + 60 * scale,
        35 * scale);

    // 小圆投影
    setfillcolor(EGERGB(20, 20, 20));
    ege_fillcircle(centerX - dialRadius + 3 * scale, // 原+3
        centerY + dialRadius - 18 * scale, // 原-18
        15 * scale); // 原半径15

    setfillcolor(EGERGB(70, 70, 70));
    ege_fillcircle(centerX - dialRadius, centerY + dialRadius - 15 * scale, 15 * scale); // 原-15
}
//螺丝

void shadowAM(float  CENTER_X, float CENTER_Y, float DIAL_RADIUS)
{
    // 使用float保证计算精度（根据需求可改为double）
    const float DIAL_RADIUS_F = (float)DIAL_RADIUS;
    const float CENTER_X_F = (float)CENTER_X;
    const float CENTER_Y_F = (float)CENTER_Y;

    // 参数化定义（精确到小数点后6位）
    const float SCREW_OFFSET = DIAL_RADIUS_F * 0.055555556f; // 1/18
    const float ELLIPSE_OFFSET_X = -DIAL_RADIUS_F * 0.111111111f; // -1/9
    const float ELLIPSE_OFFSET_Y = -DIAL_RADIUS_F * 0.166666667f; // -1/6
    const float ELLIPSE_SIZE = DIAL_RADIUS_F * 0.277777778f;  // 5/18
    const float RECT_OFFSET_X = DIAL_RADIUS_F * 0.222222222f;  // 2/9
    const float RECT_OFFSET_Y = DIAL_RADIUS_F * 0.333333333f;  // 1/3
    const float RECT_WIDTH = DIAL_RADIUS_F * 0.555555556f;   // 5/9
    const float RECT_HEIGHT = DIAL_RADIUS_F * 0.611111111f;  // 11/18
    const float CROSS_OFFSET1 = DIAL_RADIUS_F * 0.055555556f;  // 1/18
    const float CROSS_OFFSET2 = DIAL_RADIUS_F * 0.027777778f;  // 1/36
    const float LINE_WIDTH = DIAL_RADIUS_F * 0.016666667f;  // 1/60

    ege_enable_aa(TRUE);

    // 绘制函数（使用浮点坐标）
    auto draw_screw = [&](float cx, float cy) {
        // 精确到小数点后6位的渐变参数
        ege_setpattern_ellipsegradient(
            ege_point{ roundf(cx), roundf(cy) }, // 最终转整数
            EGEACOLOR(0xFF, BLACK),
            roundf(cx + ELLIPSE_OFFSET_X),
            roundf(cy + ELLIPSE_OFFSET_Y),
            roundf(ELLIPSE_SIZE),
            roundf(ELLIPSE_SIZE),
            EGEACOLOR(0, WHITE)
        );
        ege_fillrect(
            roundf(cx - RECT_OFFSET_X),
            roundf(cy - RECT_OFFSET_Y),
            roundf(RECT_WIDTH),
            roundf(RECT_HEIGHT)
        );

        // 灰色渐变层（精确尺寸调整）
        const float adjusted_size = ELLIPSE_SIZE - DIAL_RADIUS_F * 0.055555556f; // 替代原-10
        ege_setpattern_ellipsegradient(
            ege_point{
              roundf(cx - SCREW_OFFSET * 0.5f),
                roundf(cy - SCREW_OFFSET * 0.5f)
            },
            EGEACOLOR(0xFF, EGERGB(170, 170, 170)),
            roundf(cx + ELLIPSE_OFFSET_X),
            roundf(cy + ELLIPSE_OFFSET_Y),
            roundf(adjusted_size),
            roundf(adjusted_size),
            EGEACOLOR(0xFF, EGERGB(20, 20, 20))
        );
        ege_fillrect(
            roundf(cx - RECT_OFFSET_X),
            roundf(cy - RECT_OFFSET_Y),
            roundf(RECT_WIDTH),
            roundf(RECT_HEIGHT)
        );

        // 十字线（亚像素级精度）
        setcolor(EGERGB(30, 30, 30));
        setlinewidth(roundf(LINE_WIDTH));

        const float cross_y = cy - CROSS_OFFSET2 * 2.0f;
        ege_line(
            roundf(cx - CROSS_OFFSET1), roundf(cross_y),
            roundf(cx + CROSS_OFFSET1), roundf(cross_y)
        );

        const float cross_x = cx;
        const float cross_y_start = cy + CROSS_OFFSET2 / 4;
        const float cross_y_end = cy - CROSS_OFFSET2 * 4.0f;
        ege_line(
            roundf(cross_x), roundf(cross_y_start),
            roundf(cross_x), roundf(cross_y_end)
        );
        };

    // 计算四个螺丝中心坐标（浮点运算）
    const float screw_radius = DIAL_RADIUS_F - SCREW_OFFSET;

    // 左上
    draw_screw(
        CENTER_X_F - screw_radius,
        CENTER_Y_F - DIAL_RADIUS_F
    );

    // 右上
    draw_screw(
        CENTER_X_F + screw_radius,
        CENTER_Y_F - DIAL_RADIUS_F
    );

    // 右下
    draw_screw(
        CENTER_X_F + screw_radius,
        CENTER_Y_F + DIAL_RADIUS_F
    );


}

//扇形遮挡IN.Hg
void  fillpie2(float  CENTER_X, float CENTER_Y, float DIAL_RADIUS)
{
    ege_enable_aa(TRUE);  // 启用抗锯齿
    setfillcolor(EGERGB(46, 46, 46));
    double dialRadius = DIAL_RADIUS;
    ege_fillpie(CENTER_X - DIAL_RADIUS - 5 * (dialRadius / 180), CENTER_Y - DIAL_RADIUS - 5 * (dialRadius / 180), 2 * (DIAL_RADIUS + 5), 2 * (DIAL_RADIUS + 5 * (dialRadius / 180)), 18, 324);
}
//扇形遮挡mb
void  fillpie1(float  CENTER_X, float CENTER_Y, float DIAL_RADIUS)
{
    ege_enable_aa(TRUE);  // 启用抗锯齿
    double dialRadius = DIAL_RADIUS;
    setfillcolor(EGERGB(46, 46, 46));
    ege_fillpie(CENTER_X - DIAL_RADIUS + 37 * (dialRadius / 180), CENTER_Y - DIAL_RADIUS + 37 * (dialRadius / 180), 2 * (DIAL_RADIUS - 37 * (dialRadius / 180)), 2 * (DIAL_RADIUS - 37 * (dialRadius / 180)), 198, 324);
}
// 角度转换函数（假设高度范围0-100对应角度0-270度）
float heightToAngle(float height) {
    return (height / 10000) * 36;
}
float heightToAngle2(float height) {
    return (height / 100) * 36;
}
float heightToAngle3(float height) {
    return (height / 1000) * 36;
    //获得飞行数据
    //float getHeightData()
    //{
    //    float a;
    //    scanf("%lf", &a);
    //    return a;
    //}
}
#include <cmath>

// 万指针
void ten_thousand(float height, float  CENTER_X, float CENTER_Y, float DIAL_RADIUS) {
    ege_enable_aa(TRUE);  // 启用抗锯齿
    double dialRadius = DIAL_RADIUS;
    double centerX = CENTER_X;
    double centerY = CENTER_Y;
    // 计算比例因子
    double scale = dialRadius / DIAL_RADIUS_BASE;

    double angle = heightToAngle(height) - 90;
    // 转换为弧度（EGE坐标系Y轴向下）
    double radian = angle * M_PI / 180.0;
    // 计算指针形状（箭头形）
    double pointerWidth = 15.0 * scale; // 指针根部宽度

    // 主方向向量
    double dirX = cos(radian);
    double dirY = sin(radian);

    // 垂直方向向量（用于计算侧边）
    double perpX = -dirY;
    double perpY = dirX;
    double pointerLength = dialRadius - 30 * scale;

    // 计算指针端点坐标
    double endX = centerX + pointerLength * dirX;
    double endY = centerY + pointerLength * dirY;

    setcolor(EGERGB(255, 255, 255));
    setlinewidth(2 * scale);

    ege_line(centerX, centerY, endX, endY);

    ege_point points3[3] = {
        // 根部中心（创建厚度效果）
        {
            static_cast<int>(centerX + pointerLength * dirX),
            static_cast<int>(centerY + pointerLength * dirY)
        },
        // 根部左侧
        {
            static_cast<int>(centerX + (pointerLength + 25 * scale) * dirX - pointerWidth * perpX),
            static_cast<int>(centerY + (pointerLength + 25 * scale) * dirY - pointerWidth * perpY)
        },
        // 根部右侧
        {
            static_cast<int>(centerX + (pointerLength + 25 * scale) * dirX + pointerWidth * perpX),
            static_cast<int>(centerY + (pointerLength + 25 * scale) * dirY + pointerWidth * perpY)
        }
    };
    setfillcolor(EGERGB(210, 210, 210));
    ege_fillpoly(3, points3);
}

// 百指针
void thousand(float height, float  CENTER_X, float CENTER_Y, float DIAL_RADIUS) {
    ege_enable_aa(TRUE);  // 启用抗锯齿
    double dialRadius = DIAL_RADIUS;
    double centerX = CENTER_X;
    double centerY = CENTER_Y;
    // 计算比例因子
    double scale = dialRadius / DIAL_RADIUS_BASE;

    double angle = heightToAngle2(height) - 90;
    // 转换为弧度（EGE坐标系Y轴向下）
    double radian = angle * M_PI / 180.0;
    // 计算指针形状（箭头形）
    double pointerWidth = 15.0 * scale; // 指针根部宽度
    double pointerLength = dialRadius - 30 * scale;

    // 主方向向量
    double dirX = cos(radian);
    double dirY = sin(radian);

    // 垂直方向向量（用于计算侧边）
    double perpX = -dirY;
    double perpY = dirX;

    // 计算四个顶点坐标
    ege_point points[4] = {
        // 尖端
        {
            static_cast<int>(centerX + (pointerLength + 10 * scale) * dirX),
            static_cast<int>(centerY + (pointerLength + 10 * scale) * dirY)
        },
        // 根部左侧
        {
            static_cast<int>(centerX - pointerWidth * perpX),
            static_cast<int>(centerY - pointerWidth * perpY)
        },
        // 根部中心（创建厚度效果）
        {
            static_cast<int>(centerX - 30 * scale * dirX),
            static_cast<int>(centerY - 30 * scale * dirY)
        },
        // 根部右侧
        {
            static_cast<int>(centerX + pointerWidth * perpX),
            static_cast<int>(centerY + pointerWidth * perpY)
        }
    };
    setfillcolor(EGERGB(210, 210, 210));
    ege_fillpoly(4, points);
}

// 千指针
void hundred(float height, float  CENTER_X, float CENTER_Y, float DIAL_RADIUS) {
    ege_enable_aa(TRUE);  // 启用抗锯齿
    double dialRadius = DIAL_RADIUS;
    double centerX = CENTER_X;
    double centerY = CENTER_Y;
    // 计算比例因子
    double scale = dialRadius / DIAL_RADIUS_BASE;

    double angle = heightToAngle3(height) - 90;
    // 转换为弧度（EGE坐标系Y轴向下）
    double radian = angle * M_PI / 180.0;
    // 计算指针形状（箭头形）
    double pointerWidth = 15.0 * scale; // 指针根部宽度
    double pointerLength = dialRadius - 30 * scale;

    // 主方向向量
    double dirX = cos(radian);
    double dirY = sin(radian);

    // 垂直方向向量（用于计算侧边）
    double perpX = -dirY;
    double perpY = dirX;

    // 最上
    // 计算四个顶点坐标
    ege_point points1[4] = {
        // 尖端
        {
            static_cast<int>(centerX + (pointerLength - 30 * scale) * dirX),
            static_cast<int>(centerY + (pointerLength - 30 * scale) * dirY)
        },
        // 根部左侧
        {
            static_cast<int>(centerX + (pointerLength - 60 * scale) * dirX - pointerWidth * perpX),
            static_cast<int>(centerY + (pointerLength - 60 * scale) * dirY - pointerWidth * perpY)
        },
        // 根部中心（创建厚度效果）
        {
            static_cast<int>(centerX + 80 * scale * dirX),
            static_cast<int>(centerY + 80 * scale * dirY)
        },
        // 根部右侧
        {
            static_cast<int>(centerX + (pointerLength - 60 * scale) * dirX + pointerWidth * perpX),
            static_cast<int>(centerY + (pointerLength - 60 * scale) * dirY + pointerWidth * perpY)
        }
    };
    setfillcolor(EGERGB(210, 210, 210));
    ege_fillpoly(4, points1);

    // 第二
    ege_point points2[3] = {
        // 尖端
        {
            static_cast<int>(centerX + (pointerLength - 30 * scale) * dirX),
            static_cast<int>(centerY + (pointerLength - 30 * scale) * dirY)
        },
        // 根部左侧
        {
            static_cast<int>(centerX - pointerWidth * perpX),
            static_cast<int>(centerY - pointerWidth * perpY)
        },
        // 根部右侧
        {
            static_cast<int>(centerX + pointerWidth * perpX),
            static_cast<int>(centerY + pointerWidth * perpY)
        }
    };
    setfillcolor(EGERGB(210, 210, 210));
    ege_fillpoly(3, points2);

    // 第三
    ege_point points3[3] = {
        // 根部中心（创建厚度效果）
        {
            static_cast<int>(centerX - 50 * scale * dirX),
            static_cast<int>(centerY - 50 * scale * dirY)
        },
        // 根部左侧
        {
            static_cast<int>(centerX - pointerWidth * perpX),
            static_cast<int>(centerY - pointerWidth * perpY)
        },
        // 根部右侧
        {
            static_cast<int>(centerX + pointerWidth * perpX),
            static_cast<int>(centerY + pointerWidth * perpY)
        }
    };
    setfillcolor(EGERGB(128, 128, 128));
    ege_fillpoly(3, points3);
    ege_fillcircle(static_cast<int>(centerX - 50 * scale * dirX),
        static_cast<int>(centerY - 50 * scale * dirY), 15 * scale);
}    //模拟数据输入
double updateheadingAM(double current_heading) {
    static int direction = 1;
    current_heading += direction * 1.5;

    //if (current_heading >= 360) direction = -1;
    //if (current_heading <= 0) direction = 1;
    return current_heading;
}
